const mongoose = require('mongoose');

const classSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  academy: {
    type: String,
    required: true,
    trim: true
  },
  stage: {
    type: String,
    required: true,
    trim: true
  },
  advisorId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Teacher'
  },
  lecturerId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Teacher'
  },
  studentCount: {
    type: Number,
    default: 0
  },
  createdAt: {
    type: Date,
    default: Date.now
  },
  updatedAt: {
    type: Date,
    default: Date.now
  }
});

// 更新时间戳中间件
classSchema.pre('findOneAndUpdate', function(next) {
  this.set({ updatedAt: Date.now() });
  next();
});

module.exports = mongoose.model('Class', classSchema);